package co.edu.usbcali.lidis.dataaccess.conexionbd;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import co.edu.usbcali.lidis.vista.Inicio;

public class ConnectionManager {
	
	private static final String driver="org.postgresql.Driver";
	private static final String url="jdbc:postgresql://localhost:5432/tesis";
	private static final String user="postgres";
	private static final String password="P0stgressql";
	
	public static Connection getConnection()throws Exception{
		Class.forName(driver);
		return DriverManager.getConnection(url, user, password);
	}
	
	public static void closeConnection(Connection connection)throws Exception{
		if(connection!=null){
			connection.close();
		}
	}

	public static void main(String[] args) {
		try {
			ResultSet rs = null;
			PreparedStatement pst = null;
			String sql = "select usu_id, usu_nombre from usuario";
			pst = getConnection().prepareStatement(sql);
			rs = pst.executeQuery();
			while (rs.next()) {
				System.out.println(rs.getString("USU_NOMBRE"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
